package com.ss.android.common.util;

import android.os.Build;
import android.view.Window;

import java.lang.reflect.Method;

public final class DeviceUtils {
    private static boolean sIsMiui = false;
    private static boolean sIsMiuiInited = false;

    public static void setMiuiStatusBarDarkMode(boolean useSystemDarkMode, Window window) {
        int statusBarDarkMode = 0;
        try {
            Class<Window> classWindow = (Class<Window>) window.getClass();
            Class classLayoutParams = Class.forName("android.view.MiuiWindowManager.LayoutParams");
            int systemDarkMode = classLayoutParams .getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE").getInt(classLayoutParams);
            Method method_setExtraFlags = classWindow.getMethod("setExtraFlags", Integer.TYPE, Integer.TYPE);
            Object[] params = new Object[2];
            if (useSystemDarkMode) {
                statusBarDarkMode = systemDarkMode;
            }
            params[0] = Integer.valueOf(statusBarDarkMode);
            params[1] = Integer.valueOf(systemDarkMode);
            method_setExtraFlags.invoke(window, params);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }

    public static boolean isMiui() {
        if (!DeviceUtils.sIsMiuiInited) {
            try {
                if (Class.forName("miui.os.Build") == null) {

                } else {
                    sIsMiui = true;
                }
            } catch (Exception v0) {
            }
            sIsMiuiInited = true;
        }

        return sIsMiui;
    }

    public static boolean isFlyme() {
        return Build.DISPLAY.startsWith("Flyme");
    }

    public static boolean isHuawei() {
        return Build.MANUFACTURER != null && Build.MANUFACTURER.contains("HUAWEI");
    }
}

